@extends('linfeng.writer.book')
@section('index')


    <div class="">
        {{--<button class="btn btn-primary" type="button" id="test">点击我显示模态框</button>--}}

               <div class="modal" id="my-modal-alert">
                     <div class="modal-dialog">
                             <div class="modal-content">
                                      <div class="modal-header">
                                                <button type="button" class="close" data-dismiss="modal">
                                                          <span aria-hidden="true">&times</span><span class="sr-only">Close</span>
                                                      </button>
                                             <h4 class="modal-title" id="modal-title">模态框</h4><span id="num"></span>
                                          </div>
                                    <!--/*modal-header*/-->
                                     <div class="modal-body">
                                         <form action="{{url('linfeng/writer/book/addbookrolls')}}" method="post">
                                             {{csrf_field()}}
                                               <div id="modal_message">
                                                   <input type="hidden" value="{{$result->id}}" name="bid">
                                                   <input type="text" placeholder="卷名" name="bookrollsname"><br>
                                                   <textarea class="form-control" rows="2"  placeholder="卷介绍" name="desc"></textarea>
                                               </div>

                                          </div>
                                      <!--/*modal-body*/-->
                                         <div class="modal-footer" id="modal-footer">
                                               <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                                              <input type="submit" class="btn btn-primary"  value="上传卷名">
                                             <!--/*modal-body*/-->
                                             </form>
                                         </div>
                                       <!--/*modal-footer*/-->
                                 </div>
                                 <!--/*modal-dialog*/-->
                         </div>
                     <!--/*modal-content*/-->
                    </div>
               <!--/*modal*/-->
              <script>
                       $(function() {
                            $("#test").click(function(){
                                        $("#my-modal-alert").modal("toggle");
                                         $(".modal-backdrop").remove();//删除class值为modal-backdrop的标签，可去除阴影
                });
            });
                    </script>
    </div>

<div class="container">
    <div class="row works">
        <div class="col-md-6">作品管理 </div>
        <div class="col-md-6">{{$result->bookname}}</div>
    </div>

    <div class="row">
        <div class="col-md-12">
            <div class="chaptersset">
            <ul id="function">
                <li style="cursor:pointer">作品设置</li>
                <li  style="cursor:pointer">草稿箱</li>
                <li  style="cursor:pointer">已发布章节</li>
            </ul>
        </div>
        </div>
    </div>
    <hr>
    <div class="row" id="min" style='background-color: rgb(249,249,249)'>
{{--           作品设置开始                         --}}
      <div style="display:none" id="minset">
        <div class="col-md-4">
            <img src="{{asset('image/books/'.$result->bookicon)}}" alt="" class="img-thumbnail "><br>
            <p class="bookname">{{$result->bookname}}</p>
        </div>
        <div class="col-md-6 chapters_main">

            <ul>
                <li>作品名称: {{$result->bookname}}</li>
                <li>作品类型: @if($result->cid==1)
                        玄幻
                    @elseif($result->cid==2)
                        科幻
                    @elseif($result->cid==3)
                        都市
                    @elseif($result->cid==4)
                        军事
                    @elseif($result->cid==5)
                        末日
                    @elseif($result->cid==6)
                        武侠
                    @elseif($result->cid==7)
                        爱情
                    @endif</li>
                <li>总共章节: {{$result->chapterssum}}</li>
                <li>章节价格: {{$result->price}}</li>
                <li>免费章节: {{$result->free}}</li>
                <li>创建时间: {{date('Y-m-d',$result->addtime)}}</li>
                <li>作品介绍: {{$result->desc}}</li>
            </ul>
            </div>
        </div>
    </div>
{{--                作品设置结束              --}}

{{--                草稿箱开始                          --}}

       <div class="write" id="write" style="display:none">
            <div class="row" style='background-color: rgb(249,249,249)'>
              <div class="col-md-3">
                <div id="writesee">
                    <ul>
                        <li style="margin-top: 5px">发布至:</li>
                        <li style="margin-top: -5px">
                            <div class="btn-group">
                                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                    第{{$mix or 0}}卷 <span class="caret"></span>
                                </button>
                                <ul class="dropdown-menu">
                                    @foreach($bookrolls as $k)
                                        <div id="ridparent">
                                            <input type="hidden" id="bid" value="{{$result->id}}">
                                            <input type="hidden" id="mix"  value="{{$mix}}">
                                            <input type="hidden" id="rid" value="{{$rid}}">
                                         </div>
                                    <li><a href="">第{{$k->bookrollssum}}卷:{{$k->bookrollsname}}</a></li>
                                    @endforeach
                                    <li><button type="button" id="test">新增卷页</button></a>
                                    </li>
                                </ul>
                            </div>
                        </li>
                    </ul>
                    <script>
                        $(function(){
                            $('#addbookrrll')
                        })
                    </script>
                </div>
              </div>

                <form action="{{url('linfeng/writer/book/addchapters')}}" method="post" onsubmit="return false">
                {{csrf_field()}}
              <div class="col-md-9">
                  <div id="button">
                    <ul>
                        <li><button class="btn btn-success" value="发布" id="gobookrolls">发布</button></li>
                        <li><button class="btn btn-defaul">数字统计</button></li>
                        <li><button class="btn btn-defaul">全部清空</button></li>
                    </ul>
                  </div>
              </div>
                </form>
            </div>


       <div class="row">
                <div class="col-md-12">
                    <div id="text">
                    <ul>
{{--                        {{ Form::textarea('chaptersname') }}--}}
                        <li><textarea class="form-control" rows="3"  placeholder="请在此输入章节名" id="text_one" name="chaptersname"></textarea></li>
                        <li><textarea class="form-control" rows="10" placeholder="请在此输正文" id="text_two" name="text"></textarea></li>
                    </ul>
                    </div>
                </div>
            </div>
        </div>
        </form>
{{--                   草稿箱结束                   --}}

{{--         已发布章节开始                --}}
<div class="site_mian" style='background-color: rgb(249,249,249)'>
<div id="site" style="display:inline">

{{--    {{url('writer/book/seechapters/'.$k->bookrollssum.'/'.$bid)}}--}}
    <div class="container ">
        <div class="row">
            <div class="col-md-3 site_parter">
                    <ul class="site_son">
                        @foreach($allbookrolls as $k)
                        <li style="cursor: pointer;" id="onsite" ><div class="site_listjuan" id="{{$k->id}}"><a name="{{$k->id}}">第{{$k->bookrollssum}}卷:{{$k->bookrollsname}}</a></div></li>
                            <hr class="site_hr">
                            @endforeach
                    </ul>

            </div>
            <div class="col-md-9" id="site_new">

            </div>
        </div>

    </div>

</div>
</div>
{{--         已发布章节结束              --}}

    {{--js已发布章节--}}
    <script>
        $(function(){

            $(this).on('click','a',$(this),function(){
               $sum=$(this).html();

                $rid=$(this).attr('name');

                $.ajax({
                    url:"{{url('linfeng/writer/book/seechapters')}}",
                    type:'post',
                    data:'sum='+$sum+'&rid='+$rid,
                    success:function(data){
                        $do=$.makeArray(data);
                            if ($do){
                                $('#site_new>ul').empty();
                            }
                        for (var i=0 ; i<$do.length;i++){
                            $('#site_new').append('<ul class="site_js"><li><b class="site_text" style="cursor: pointer;" name='+$do[i].id+'>第'+$do[i].chapterssum+'章'+$do[i].chaptersname+'</b></li></ul>')
                        }
                    },
                    headers: {
                        {{--'X-CSRF-TOKEN' : '{{ csrf_token() }}'--}}
                        'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                    },
                    error:function(){
                        alert('失败！');
                    },
                    dataType:'json'
                })
            })
        })
    </script>

    {{--   js章节正文   --}}
    <script>
        $(function(){
            $(this).on('click','b',function(){
                $('#site_new>ul').empty();
                $id=$(this).attr('name');
//                alert($id);
                $.ajax({
                    url:'{{url('linfeng/writer/book/seechapters/text')}}',
                    type:'get',
                    data:'id='+$id,
                    success:function(data){
                        alert(data);
                        $('#site_new').append('')
                    },
                    error:function(){
                        alert('失败');
                    },
                    dataType:'text'
                })

            })
        })

    </script>



    {{--js控制选项卡--}}
<script>
    $(function(){
        $('#function>li').click(function(){
            switch($(this).html()){
                case '作品设置':
                    $("#site").css('display','none');
                    $("#write").css('display','none');
                    $("#minset").css('display','inline');
                    break;
                case '草稿箱':
                    $("#site").css('display','none');
                    $("#minset").css('display','none');
                    $("#write").css('display','inline');
                    break;
                case '已发布章节':
                    $("#minset").css('display','none');
                    $("#write").css('display','none');
                    $("#site").css('display','inline');
            }
        });
    })
</script>

    {{--ajax上传textarea文本域--}}
    <script>
        $(function(){
            $('#gobookrolls').click(function(){
                $text_one=$('#text_one').val();
                $text_wto=$('#text_two').val();
                $token=$('#_token').val();
                $bid=$('#bid').val();
                $mix=$('#mix').val();
                $rid=$('#rid').val();
                $.ajax({
                    url:"{{url('linfeng/writer/book/addchapters')}}",
                    type:'post',

                    data:'text_one='+$text_one+'&text_two='+$text_wto+'&_token='+$token+'&bid='+$bid+'&rid='+$rid+'&mix='+$mix,
                    success:function(data){
                        if (data){
                            if (data){
                                alert('新增章节成功');
                                window.location.reload();
                            }
                        }
                    },
                    headers: {
                        {{--'X-CSRF-TOKEN' : '{{ csrf_token() }}'--}}
                        'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                    },
                    error:function(){
                        alert('失败！');
                    },
                    dataType:'text'
                })
            })
        })

    </script>
    <meta name="_token" content="{!! csrf_token() !!}"/>
    <input type="hidden" id="_token" value="{{csrf_token()}}">
    {{--ajax上传textarea文本域结束--}}
    @endsection